// AWTList.h: interface for the AWTList class.
//
//////////////////////////////////////////////////////////////////////

//14/01/2000 jrd	ref 14673	increases visible rows to 10

#if !defined(AFX_AWTLIST_H__00A74EC5_7F93_11D2_A427_006097A44215__INCLUDED_)
#define AFX_AWTLIST_H__00A74EC5_7F93_11D2_A427_006097A44215__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "AWTComponent.h"

//#define DEFAULT_VISIBLE_ROWS   4
#define DEFAULT_VISIBLE_ROWS   10 //jd 14/1/2000

class AFX_EXT_CLASS AWTList : public AWTComponent,
													    public AWTItemSelectable
{
DECLARE_DYNAMIC(AWTList)
public:
	AWTList();
	AWTList(int rows);
	AWTList(int rows, BOOL multipleMode);
	virtual ~AWTList();

	int getItemCount() 
		{return countItems(); }
	int countItems() 
		{return m_items.GetCount();}
	CString& getItem(int index);
  void add(LPTSTR item)
		{addItem(CString(item));}
  void add(CString& item) 
		{addItem(item);}
	void addItem(CString& item) 
		{addItem(item, -1);}
	void addItem(CString& item, int index);
	void replaceItem(CString& newValue, int index);
	void removeAll() 
		{clear();}
	void clear();
	void remove(CString& item);
	void remove(int position) 
		{delItem(position);}
	void delItem(int position) 
		{delItems(position, position);}
	CString& getSelectedItem();
	CStringArray* getSelectedItems(); 
	void select(int index);
	void deselect(int index);
	void select(CString& item);
	BOOL isIndexSelected(int index) 
		{return isSelected(index);}
	BOOL isSelected(int index);
	int getRows() 
		{return m_rows;}
	BOOL isMultipleMode() 
		{return allowsMultipleSelections();}
	BOOL allowsMultipleSelections() 
		{return m_multipleMode;}
	void setMultipleMode(BOOL b) 
		{setMultipleSelections(b);}
	void setMultipleSelections(BOOL b);
	int getVisibleIndex() 
		{return m_visibleIndex;}
	void makeVisible(int index);
	void getSelectedIndexes(int** indexes, int* cnt);
	int getSelectedIndex();

	void set3DBorder(BOOL b)
		{m_b3DBorder = b;}
	BOOL get3DBorder()
		{return m_b3DBorder;}

	virtual CWnd* createComponent();
	virtual CSize getMinimumSize();
	virtual CSize getPreferredSize();

	virtual CStringArray* getSelectedObjects()
		{return getSelectedItems();}
	virtual AWTObject* getObject()
		{return this;}

	virtual void addActionListener(AWTActionListener* l) 
		{m_actionListener = AWTEventMulticaster::add(m_actionListener, l);}
  virtual void removeActionListener(AWTActionListener* l) 
		{m_actionListener = AWTEventMulticaster::remove(m_actionListener, l);}
	virtual void processActionEvent(AWTActionEvent* e);
	virtual void addItemListener(AWTItemListener* l) 
		{m_itemListener = AWTEventMulticaster::add(m_itemListener, l);}
  virtual void removeItemListener(AWTItemListener* l) 
		{m_itemListener = AWTEventMulticaster::remove(m_itemListener, l);}
	virtual void processItemEvent(AWTItemEvent* e);
	virtual BOOL isFocusTraversable()
		{return TRUE;}

private:
	void delItems(int start, int end);
	void construct(int rows, BOOL multipleMode)
	{
		m_rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS; 
		m_multipleMode = multipleMode;
		m_selected = NULL;
		m_visibleIndex = -1;
		m_actionListener = NULL;
		m_itemListener = NULL;
		m_selectedLength = 0;
		if (!m_multipleMode)
			select(0);
		setBackground(AWTColor::white());
		setForeground(AWTColor::black());
		m_b3DBorder = TRUE;
	}

protected:
	CStringList m_items;
	int m_rows;
	BOOL m_multipleMode;
	int* m_selected;
	int m_selectedLength;
	int m_visibleIndex;
	AWTActionListener* m_actionListener;
	AWTItemListener* m_itemListener;
	CString m_nullString;
	BOOL m_b3DBorder;
};



#endif // !defined(AFX_AWTLIST_H__00A74EC5_7F93_11D2_A427_006097A44215__INCLUDED_)
